{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "import tensorflow as tf\r\n",
    "import numpy as np"
   ],
   "outputs": [],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "source": [
    "x = tf.random.normal((1,2,2,3))\r\n",
    "x.shape"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "TensorShape([1, 2, 2, 3])"
      ]
     },
     "metadata": {},
     "execution_count": 27
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "source": [
    "ax = tf.keras.layers.GlobalAveragePooling2D()(x)\r\n",
    "ax.shape"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "TensorShape([1, 3])"
      ]
     },
     "metadata": {},
     "execution_count": 28
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "source": [
    "x"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(1, 2, 2, 3), dtype=float32, numpy=\n",
       "array([[[[ 1.0732665 , -0.316923  ,  0.34387082],\n",
       "         [ 0.85719526,  0.383818  ,  0.0714375 ]],\n",
       "\n",
       "        [[ 2.07628   ,  1.0945694 ,  0.6519038 ],\n",
       "         [ 0.00441903,  1.2396817 ,  0.10125866]]]], dtype=float32)>"
      ]
     },
     "metadata": {},
     "execution_count": 29
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "source": [
    "ax"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(1, 3), dtype=float32, numpy=array([[1.0027902 , 0.60028654, 0.29211769]], dtype=float32)>"
      ]
     },
     "metadata": {},
     "execution_count": 30
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "source": [
    "aaa = 1.0732665+0.85719526+2.07628+0.00441903\r\n",
    "aaa/4"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "1.0027901975000002"
      ]
     },
     "metadata": {},
     "execution_count": 31
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "source": [
    "a1 = tf.random.normal((2,2,2,3))\r\n",
    "a1.shape"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "TensorShape([2, 2, 2, 3])"
      ]
     },
     "metadata": {},
     "execution_count": 32
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "source": [
    "a1"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(2, 2, 2, 3), dtype=float32, numpy=\n",
       "array([[[[-0.76654285,  1.79131   ,  1.0236188 ],\n",
       "         [-0.6119361 , -1.5272698 , -0.364413  ]],\n",
       "\n",
       "        [[ 0.07261603,  0.57860726,  0.4255542 ],\n",
       "         [-0.57528603,  0.74275184,  0.07588626]]],\n",
       "\n",
       "\n",
       "       [[[ 0.84789306,  1.2030426 , -1.7836232 ],\n",
       "         [ 0.6010358 ,  1.3016247 , -0.7656161 ]],\n",
       "\n",
       "        [[ 0.34526846,  2.0315964 ,  0.1813532 ],\n",
       "         [-0.7089366 ,  0.6344181 ,  0.973302  ]]]], dtype=float32)>"
      ]
     },
     "metadata": {},
     "execution_count": 34
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "source": [
    "pa1 = tf.keras.layers.GlobalAveragePooling2D()(a1)\r\n",
    "pa1.shape"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "TensorShape([2, 3])"
      ]
     },
     "metadata": {},
     "execution_count": 33
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "source": [
    "pa1"
   ],
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": [
       "<tf.Tensor: shape=(2, 3), dtype=float32, numpy=\n",
       "array([[-0.47028726,  0.3963498 ,  0.29016155],\n",
       "       [ 0.2713152 ,  1.2926704 , -0.34864607]], dtype=float32)>"
      ]
     },
     "metadata": {},
     "execution_count": 35
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "source": [],
   "outputs": [],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.7.1",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.7.1 64-bit ('KerasEnv': virtualenv)"
  },
  "interpreter": {
   "hash": "49709926ca079d7fc3208f0b0481edbe733516c473689c5f1439ce0f2246de88"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}